<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <ui:composition template="layout.xhtml">

        <ui:define name="title">
            Pesquisar Saída
        </ui:define>

        <ui:define name="content">           
            <h:form id="pesquisarSaidaForm">    

                <p:messages id="pesquisarSaidaMessages" autoUpdate="true" />

                <div class="actions">
                    <div id="buttons">
                        <p:button value="Cadastrar Saída" outcome="criarSaida.xhtml"
                                  icon="ui-icon-plus" styleClass="ui-priority-primary">
                        </p:button>
                    </div>
                </div>

                <p:fieldset legend="Filtros" id="dadosFieldset">
                    <f:validateBean disabled="true">

                        <div class="row">
                            <div class="column2">
                                <p:outputLabel value="Tipo da Saída" for="tipoSaidaAutoComplete" />
                            </div>
                            <div class="column3">
                                <p:autoComplete id="tipoSaidaAutoComplete" value="#{ managerPesquisarSaida.saidaPesquisar.tipoSaida }"
                                                forceSelection="true" dropdown="true" var="tipoSaida" itemValue="#{ tipoSaida }" 
                                                itemLabel="#{ tipoSaida.descricao }" completeMethod="#{ managerPesquisarSaida.autocompletarTipoSaida }"
                                                converter="conversortiposaida" minQueryLength="3"/>
                            </div>

                            <div class="column3">
                                <p:outputLabel value="Data da Saída" for="dataSaidaInputText" />
                            </div>
                            <div class="column3">
                                <p:calendar id="dataSaidaInputText" value= "#{ managerPesquisarSaida.saidaPesquisar.dataSaida }"
                                            showOn="button" pattern="dd/MM/yyyy" locale="pt" navigator="true"/>
                            </div>
                        </div>

                        <div class="row">
                            <div class="column2">
                                <p:outputLabel value="Descrição" for="descricaoInputTextarea" />
                            </div>
                            <div class="column9">
                                <p:inputTextarea id="descricaoInputTextarea"
                                                 value="#{ managerPesquisarSaida.saidaPesquisar.descricao }"/>
                            </div>
                        </div>

                    </f:validateBean>
                </p:fieldset>

                <div class="command">
                    <p:commandButton
                        id="pesquisarcommandButton" value="Pesquisar" icon="ui-icon-search"                                 
                        styleClass="ui-priority-primary" oncomplete="widthFix();"
                        update="@form" actionListener="#{ managerPesquisarSaida.pesquisar() }" />
                    <p:commandButton value="Limpar" icon="ui-icon-close" update="@form" oncomplete="widthFix();"
                                     actionListener="#{ managerPesquisarSaida.limpar() }" />
                </div>

                <p:dataTable id="saidasDataTable" var="saida" value="#{ managerPesquisarSaida.saidas }"
                             rows="10" paginator="true" paginatorPosition="bottom" emptyMessage="Nenhum Saída encontrado">

                    <p:column width="5%" headerText="Opções">
                        <div class="options1">
                            <p:button
                                title="Visualizar" href="visualizarSaida.xhtml?saidaId=#{ saida.id }"
                                icon="ui-icon-search"/>
                        </div>
                    </p:column>

                    <p:column headerText="Nome" width="25%">
                        <h:outputText value="#{ saida.tipoSaida.descricao }" />
                    </p:column>

                    <p:column headerText="Descrição" width="45%">
                        <h:outputText value="#{ saida.descricao }" />
                    </p:column>                    
                    
                    <p:column headerText="Data da Saída" width="25%">
                        <h:outputText value="#{ saida.dataSaida }">
                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                        </h:outputText>
                    </p:column>
                </p:dataTable>


                <p:dialog header="Deseja realmente excluir?" widgetVar="dialogApagar" modal="true"
                          closable="false" resizable="false" draggable="false" >
                    <div class="commandDialog">
                        <p:commandButton value="Sim" update=":pesquisarSaidaForm:saidasDataTable"
                                         oncomplete="dialogApagar.hide()" icon="ui-icon-check" actionListener="#{ managerPesquisarSaida.deletar() }" />
                        <p:commandButton value="Não" icon="ui-icon-close" oncomplete="dialogApagar.hide()" />
                    </div>
                </p:dialog>

            </h:form>
        </ui:define>
    </ui:composition>

</html>